<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            title="云端登录"
            :async="true"
            width="550px"
            @confirm="handleSubmit"
            @close="handleClose"
            cancelButtonText=""
        >
            <el-form
                ref="formRef"
                :model="formData"
                label-width="84px"
                :rules="formRules"
            >
                <el-form-item label="账号" prop="account">
                    <el-input
                        v-model="formData.account"
                        placeholder="请输入账号"
                        clearable
                    />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input
                        v-model="formData.password"
                        placeholder="请输入密码"
                        clearable
                    />
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from "element-plus";
import {
    articleCateEdit,
    articleCateAdd,
    articleCateDetail,
} from "@/api/article";
import Popup from "@/components/popup/index.vue";
import axios from "axios";
import cache from "@/utils/cache";
import { ElMessage } from "element-plus";
const emit = defineEmits(["success", "close"]);
const formRef = shallowRef<FormInstance>();
const popupRef = shallowRef<InstanceType<typeof Popup>>();
const mode = ref("add");
const formData = reactive({
    account: "",
    password: "",
});
const formRules = {
    account: [
        {
            required: true,
            message: "请输入账号",
            trigger: ["blur"],
        },
    ],
    password: [
        {
            required: true,
            message: "请输入密码",
            trigger: ["blur"],
        },
    ],
};
const configData = cache.get("configData");
const handleSubmit = async () => {
    await formRef.value?.validate();
    emit("success", { account: formData.account, password: formData.password });

};

const open = () => {
    popupRef.value?.open();
};

const setFormData = (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key];
        }
    }
};

// const getDetail = async (row: Record<string, any>) => {
//     const data = await articleCateDetail({
//         id: row.id
//     })
//     setFormData(data)
// }

const handleClose = () => {
    emit("close");
};

defineExpose({
    open,
    setFormData,
    // getDetail
});
</script>
